import java.util.*;
 class TreeNode {
     int val;
     TreeNode left;
     TreeNode right;
     TreeNode(int x) { val = x; }
 }


public class BinaryTreePostorderTraversal {
    public static List<Integer> postorderTraversal(TreeNode root) {
        List<Integer> result = new ArrayList<Integer>();

        postorderTraversalInternal(root,result);

        return result;
 
    }

    public static void postorderTraversalInternal(TreeNode root,List<Integer> result) {
        if(root == null) return;
        postorderTraversalInternal(root.left,result);
        postorderTraversalInternal(root.right,result);
        result.add(root.val);
    }

    
    public static void main(String[] args) {
        TreeNode root = new TreeNode(1);
        TreeNode right1 = new TreeNode(2);
        TreeNode left2 = new TreeNode(3);

        root.right = right1;
        right1.left = left2;

        System.out.println(postorderTraversal(root));
        
    }
}